package com.pucheng.bracelet.ui.activity.watch

import android.os.Bundle
import android.view.View
import androidx.lifecycle.observe
import com.blankj.utilcode.util.TimeUtils
import com.pucheng.bracelet.R
import com.pucheng.bracelet.app.util.BandPeriodFormat
import com.pucheng.bracelet.app.util.DateFormat
import com.pucheng.bracelet.app.util.click
import com.pucheng.bracelet.ui.dialog.TimeSelectDialog
import com.pucheng.bracelet.viewmodel.EffectivePeriodViewModel
import kotlinx.android.synthetic.main.activity_period_chooce.*
import me.hgj.jetpackmvvm.base.activity.BaseVmActivity
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel

class EffectivePeriodActivity : BaseVmActivity<EffectivePeriodViewModel>() {
    override fun createObserver() {
        mViewModel.apply {
            startTime.observe(this@EffectivePeriodActivity) {
                tv_start_time.text = BandPeriodFormat.timeFormat(this@EffectivePeriodActivity,it)
            }
            endTime.observe(this@EffectivePeriodActivity) {
                tv_end_time.text = BandPeriodFormat.timeFormat(this@EffectivePeriodActivity,it)
            }
        }
    }

    override fun dismissLoading() {
    }

    override fun initView(savedInstanceState: Bundle?) {
        tv_title.text = getString(R.string.quick_view_period)
        tv_cancel.click { finish() }
        tv_save.click {
            mViewModel.saveData()
            finish()
        }
        rel_start_time.click {
            TimeSelectDialog(this, mViewModel.startTime.value!!).setOnTimeSelectCallBack(object :
                TimeSelectDialog.TimeSelectCallBack {
                override fun onSelectTime(time: String?) {
                    tv_start_time.text = BandPeriodFormat.timeFormat(this@EffectivePeriodActivity,time)
                    mViewModel.startTime.value = time
                }
            }).show()
        }
        rel_end_time.click {
            TimeSelectDialog(this, mViewModel.endTime.value!!).setOnTimeSelectCallBack(object :
                TimeSelectDialog.TimeSelectCallBack {
                override fun onSelectTime(time: String?) {
                    tv_end_time.text =
                        BandPeriodFormat.timeFormat(this@EffectivePeriodActivity, time)
                    mViewModel.endTime.value = time
                }
            }).show()
        }
        tv_do_not_disturb_hint.visibility = View.GONE
    }

    override fun layoutId(): Int = R.layout.activity_period_chooce

    override fun showLoading(message: String) {
    }
}